package jdbctest;

import com.alibaba.druid.support.spring.stat.annotation.Stat;

import javax.swing.plaf.nimbus.State;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try(Connection connection = DBUtil.getConnection()) {
            Statement statement = connection.createStatement();
            String sql = "SELECT id,name,salary,title\n"+
                    "FROM teacher";
            ResultSet rs = statement.executeQuery(sql);
            while(rs.next()){
                int id = rs.getInt(1);
                String name = rs.getString(2);
                int salary = rs.getInt(3);
                String title = rs.getString(4);
                String line = String.join(",",id+"",name,salary+"",title);
                System.out.println(line);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
